package utils;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class RabbitMQUtils {

    private static final String host = "116.205.167.172";
    private static final int port = 5672;
    private static final String userName= "admin";
    private static final String password= "NARkGHzn";

    public static Channel getChannel(){
        //创建一个连接工厂
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost(host);
        factory.setPort(port);
        factory.setUsername(userName);
        factory.setPassword(password);
        Connection connection = null;
        Channel channel = null;
        try {
            connection= factory.newConnection();
            //获取信道
            channel = connection.createChannel();
        }catch (Exception e){
            log.error("获取交换机失败");
        }
        return channel;
    }
}
